package com.zsck.pos.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chinaums.commoncheck.R;
import com.zsck.pos.bean.Bill;
import com.zsck.pos.bean.FeeListBean;

import java.util.ArrayList;
import java.util.List;


public class BillFeeAdapter extends ContentAdapter<FeeListBean> {

    public BillFeeAdapter(Context context,List<FeeListBean> mRecords){
        super(context,mRecords);
    }

    @Override
    public int getCount() {
        return mItems.size();
    }

    @Override
    public FeeListBean getItem(int position) {
        return mItems.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView == null){
            convertView = View.inflate(context, R.layout.item_bill_fee,null);
            holder = new ViewHolder();
            holder.cbSelect = convertView.findViewById(R.id.cb_select);
            holder.tvMoney = convertView.findViewById(R.id.tv_fee);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        FeeListBean item = getItem(position);
        holder.cbSelect.setText(item.getName());
        holder.tvMoney.setText("¥" + item.getAmount());


        holder.cbSelect.setChecked(mSelectedIndex.contains(item));

        holder.cbSelect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mSelectedIndex.contains(item)){
                    mSelectedIndex.remove(item);
                }else{
                    mSelectedIndex.add(item);
                }
                if(mCallBack != null){
                    mCallBack.onSelectedChange(mSelectedIndex,isAllSelected());
                }
                notifyDataSetChanged();
            }
        });


        return convertView;
    }


    static class ViewHolder{
        TextView tvName;
        TextView tvStatus;
        TextView tvProject;
        TextView tvMoney;
        TextView tvCost;
        TextView tvIn;
        CheckBox cbSelect;
        TextView tvWho;
    }
}
